package com.cloudsigns.factorymanager2.produce.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.bean.AccountInfoBean;
import com.cloudsigns.factorymanager2.project.customview.GlideCircleTransform;

import java.util.ArrayList;
import java.util.List;

public class ProduceAttendanceListAdapter extends BaseAdapter{

    private Context context;
    private List<AccountInfoBean> datas = new ArrayList<AccountInfoBean>();
    private LayoutInflater inflater;

    public ProduceAttendanceListAdapter(Context context) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    public void setData(List<AccountInfoBean> list) {
        this.datas.clear();
        if (null != list) {
            this.datas.addAll(list);
        }
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public AccountInfoBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_produce_attendance_list, null);
            holder.img_personnel_head = convertView.findViewById(R.id.img_personnel_head);
            holder.tv_personnel_name = convertView.findViewById(R.id.tv_personnel_name);
            holder.tv_personnel_data = convertView.findViewById(R.id.tv_personnel_data);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        AccountInfoBean accountInfoBean = datas.get(position);
        holder.tv_personnel_name.setText(accountInfoBean.getAccountName());

        Glide.with(context).load(accountInfoBean.getAvatar()).bitmapTransform(new GlideCircleTransform(context)).crossFade(1000).error(R.mipmap.default_avatar).into(holder.img_personnel_head);

        return convertView;
    }

    private class ViewHolder {
        private ImageView img_personnel_head;
        private TextView tv_personnel_name;
        private TextView tv_personnel_data;
    }
}
